//
//  C_MVViewController.m
//  音悦咖
//
//  Created by Best on 15/7/15.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

//http://api.dongting.com/song/video/2000618?app=ttpod&v=v7.9.4.2015052918&uid=&mid=iPhone7%2C1&f=f320&s=s310&imsi=&hid=&splus=8.3&active=1&net=2&openudid=07afc257564998d95c30d3961b852009acbd4bc7&idfa=344D8202-B8A1-4025-8A03-D1D21F9B1723&utdid=VZ9EyvXI9JADAKFnFQwx0zo5&alf=201200&bundle_id=com.ttpod.music
//http://api.dongting.com/sim/mv/2000616/similarity?app=ttpod&v=v7.9.4.2015052918&uid=&mid=iPhone4S&f=f320&s=s310&imsi=&hid=&splus=8.0&active=1&net=2&openudid=b55e125b1cbcd2f8d637e5573f9a6f6f241e0c3f&idfa=DD02B768-7FEA-48C3-A977-931093C926A0&utdid=VZ5%2FNAYMGNwDAGGSKGx50btO&alf=201200&bundle_id=com.ttpod.music
#import "C_MVViewController.h"
#import "C_BaseMovePlayerViewController.h"

#define API_MV_URL_FOUNT    @"http://api.dongting.com/song/video/"
#define API_MV_URL_BACK     @"?app=ttpod&v=v7.9.4.2015052918&uid=&mid=iPhone7%2C1&f=f320&s=s310&imsi=&hid=&splus=8.3&active=1&net=2&openudid=07afc257564998d95c30d3961b852009acbd4bc7&idfa=344D8202-B8A1-4025-8A03-D1D21F9B1723&utdid=VZ9EyvXI9JADAKFnFQwx0zo5&alf=201200&bundle_id=com.ttpod.music"

#define API_LIST_URL_FOUNT       @"http://api.dongting.com/sim/mv/"
#define API_LIST_URL_BACK      @"/similarity?app=ttpod&v=v7.9.4.2015052918&uid=&mid=iPhone4S&f=f320&s=s310&imsi=&hid=&splus=8.0&active=1&net=2&openudid=b55e125b1cbcd2f8d637e5573f9a6f6f241e0c3f&idfa=DD02B768-7FEA-48C3-A977-931093C926A0&utdid=VZ5%2FNAYMGNwDAGGSKGx50btO&alf=201200&bundle_id=com.ttpod.music"

@interface C_MVViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, retain) NSMutableArray *mvArr;

@end

@implementation C_MVViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = RGBA(100, 100, 100, 1);
    self.titleLabel.text = @"MV";
    backgroundImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 49)];
    backgroundImage.image = [UIImage imageWithContentsOfFile:GETBUNDLE_PATH(@"blackgound", @"jpg")];
    [self.view addSubview:backgroundImage];
    backgroundImage.userInteractionEnabled = YES;
    [backgroundImage release];

    [self getdata];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




#pragma mark GetData
- (void)getdata
{
     [AFNetworkHandler GETWithAFNByURL:self.MV_url completion:^(id result) {
         
         self.mvArr = [MVModel arrayWithModelByArray:[result objectForKey:@"data"]];
         [self createCollection];
         
     }];
}


#pragma mark CreateCollection
- (void)createCollection
{
    MvLayout = [[[UICollectionViewFlowLayout alloc] init] autorelease];
    MvLayout.minimumLineSpacing = 1;
    
    MvCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 49 - 64) collectionViewLayout:MvLayout];
    MvLayout.itemSize = CGSizeMake(MvCollection.frame.size.width, MvCollection.frame.size.width - 150);
    MvCollection.delegate = self;
    MvCollection.dataSource = self;
    [backgroundImage addSubview:MvCollection];
    [MvCollection release];
    
    [MvCollection registerClass:[C_MVCollectionViewCell class] forCellWithReuseIdentifier:@"C_MVCollectionViewCell"];
    
}

#pragma mark collection Delegate 

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.mvArr.count;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    C_MVCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"C_MVCollectionViewCell" forIndexPath:indexPath];
    
    cell.model = self.mvArr[indexPath.item];
    
    if (!indexPath.item) {
        cell.dayTitleLabel.textColor = [UIColor cyanColor];
    }
    return cell;
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    C_BaseMovePlayerViewController *moveplayer = [[C_BaseMovePlayerViewController alloc] init];
    moveplayer.movePlayer_url = [NSString stringWithFormat:@"%@%@%@", API_MV_URL_FOUNT, [self.mvArr[indexPath.item] mainId], API_MV_URL_BACK];
   // NSLog(@"%@", moveplayer.movePlayer_url);
    moveplayer.movieList_url = [NSString stringWithFormat:@"%@%@%@", API_LIST_URL_FOUNT, [self.mvArr[indexPath.item] mainId], API_LIST_URL_BACK];
    [self presentViewController:moveplayer animated:YES completion:^{
        
        
    }];
    
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
